package mobile.game.rpc;
                    
import mobile.game.core.CallPoint;
import mobile.game.core.Port;
import mobile.game.core.support.Param;
import mobile.game.core.support.Utils;
import mobile.game.core.support.function.*;
import mobile.game.core.gen.proxy.RPCProxyBase;
import mobile.game.core.gen.JowGenFile;


@SuppressWarnings("all")
@JowGenFile
public final class AccountServiceProxy extends RPCProxyBase {
	public final class EnumCall{
		public static final int MOBILE_GAME_RPC_ACCOUNTSERVICE_DISPATCH = 1;
	}
	
	private CallPoint remote;
	private Port localPort;
	private String callerInfo;
	
	/**
	 * 私有构造函数
	 * 防止实例被私自创建 必须通过newInstance函数
	 */
	private AccountServiceProxy() {}

	
	/**
	 * 获取实例
	 * @return
	 */
	public static AccountServiceProxy newInstance(CallPoint targetPoint) {
		return createInstance(targetPoint.nodeId, targetPoint.portId, targetPoint.servId);
	}
	
	/**
	 * 获取实例
	 * @return
	 */
	public static AccountServiceProxy newInstance(String node, String port, Object id) {
		return createInstance(node, port, id);
	}
	
	/**
	 * 创建实例
	 * @param localPort
	 * @param node
	 * @param port
	 * @param id
	 * @return
	 */
	private static AccountServiceProxy createInstance(String node, String port, Object id) {
		AccountServiceProxy inst = new AccountServiceProxy();
		inst.localPort = Port.getCurrent();
		inst.remote = new CallPoint(node, port, id);
		
		return inst;
	}
	
	/**
	 * 监听返回值
	 * @param obj
	 * @param methodName
	 * @param context
	 */
	public void listenResult(JowFunction2<Param, Param> method, Object...context) {
		listenResult(method, new Param(context));
	}
	
	/**
	 * 监听返回值
	 * @param obj
	 * @param methodName
	 * @param context
	 */
	public void listenResult(JowFunction2<Param, Param> method, Param context) {
		context.put("_callerInfo", callerInfo);
		localPort.listenResult(method, context);
	}
	
	
	public void listenResult(JowFunction3<Boolean, Param, Param> method, Object...context) {
		listenResult(method, new Param(context));
	}
	
	public void listenResult(JowFunction3<Boolean, Param, Param> method, Param context) {
		context.put("_callerInfo", callerInfo);
		localPort.listenResult(method, context);
	}
	
	
	/**
	 * 等待返回值
	 */
	public Param waitForResult() {
		return localPort.waitForResult();
	}
	
	public void dispatch() {
		callerInfo = Utils.getCallerInfo();
		localPort.call(remote, EnumCall.MOBILE_GAME_RPC_ACCOUNTSERVICE_DISPATCH, new Object[]{  });
	}
}